home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Xconq 7.0d37 / source / kernel / unit.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-02  |  23.2 KB  |  575 lines  |  [TEXT/KAHL]

  1. /* Definitions relating to units in Xconq.
  2.    Copyright (C) 1987, 1988, 1989, 1991, 1992, 1993, 1994, 1995
  3.    Stanley T. Shebs.
  4.  
  5. Xconq is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.  See the file COPYING.  */
  9.  
  10. /* The unit structure should be small, because there may be many of them.
  11.    Unit semantics go in this structure, while unit brains go into the
  12.    act/plan.  Test: a unit that is like a rock and can't do anything at all
  13.    just needs basic slots, plan needn't be allocated.  Another test:
  14.    unit should still function correctly after its current plan has been
  15.    destroyed and replaced with another. */
  16.  
  17. typedef struct a_unit {
  18.     short type;            /* type */
  19.     short id;              /* truly unique id number */
  20.     char *name;            /* the name, if given */
  21.     long number;               /* semi-unique number */
  22.     short x, y, z;             /* position of unit in world */
  23.     struct a_side *side;    /* whose side this unit is on */
  24.     short hp;              /* how much more damage each part can take */
  25.     short hp2;             /* buffer for next value of hp */
  26.     short cp;              /* state of construction */
  27.     short cxp;             /* combat experience */
  28.     short morale;              /* morale */
  29.     struct a_unit *transport;    /* pointer to transporting unit if any */
  30. #if (MAXMTYPES > 2)
  31.     short *supply;             /* how much supply we're carrying (dynalloc) */
  32. #else
  33.     short supply[MAXMTYPES];    /* how much supply we're carrying */
  34. #endif
  35. #if (MAXSIDES < 30)
  36.     long spotted;        /* which sides always see us (bit vector) */
  37. #else
  38.     char spotted[MAXSIDES];    /* which sides always see us (array) */
  39. #endif
  40.     short *tooling;            /* level of preparation for construction */
  41.     short *opinions;        /* opinion of each side, own side and others */
  42.     struct a_actorstate *act;    /* the unit's current actor state */
  43.     struct a_plan *plan;    /* the unit's current plan */
  44.     Obj *hook;             /* placeholder for optional stuff */
  45.     char *aihook;        /* used by AI to keep info about this unit */
  46.     char *uihook;        /* used by interfaces for their own purposes */
  47.     /* Following slots are never saved. */
  48.     struct a_unit *occupant;    /* pointer to first unit being carried */
  49.     struct a_unit *nexthere;    /* pointer to fellow occupant */
  50.     struct a_unit *prev;    /* previous unit in list of side's units */
  51.     struct a_unit *next;    /* next unit in list of side's units */
  52.     struct a_unit *unext;    /* next unit in list of all units */
  53.     short prevx, prevy;        /* where were we last */
  54. } Unit;
  55.  
  56. /* Some convenient macros. */
  57.  
  58. /* Since it is possible for a unit to change sides and therefore
  59.    prev/next pointers while iterating using the macros below, one
  60.    must be very careful either that unit sides can't change during
  61.    the loop, or else to maintain a temp var that can be used to
  62.    repair the iteration.  This also applies to units dying. */
  63.  
  64. /* Iteration over all units. */
  65. /* Careful with this one, can run afoul of precedence rules since no
  66.    brace to enclose the outer loop. */
  67.  
  68. #define for_all_units(v)  \
  69.     for (v = unitlist; v != NULL; v = v->unext)
  70.  
  71. /* Iteration over all units on a given side. */
  72.  
  73. #define for_all_side_units(s,v) \
  74.     for (v = (s)->unithead->next; v != (s)->unithead; v = v->next)
  75.  
  76. /* Iteration over all occupants of a unit (but not sub-occupants). */
  77.  
  78. #define for_all_occupants(u1,v) \
  79.   for (v = (u1)->occupant; v != NULL; v = v->nexthere)
  80.  
  81. #define is_unit(unit) ((unit) != NULL && is_unit_type((unit)->type))
  82.  
  83. #define alive(unit) ((unit)->hp > 0)
  84.  
  85. #define indep(unit) ((unit)->side == NULL || (unit)->side == indepside)
  86.  
  87. #define completed(unit) \
  88.   ((unit)->cp >= (u_cp((unit)->type) / u_parts((unit)->type)))
  89.  
  90. #define fullsized(unit) \
  91.   ((unit)->cp >= u_cp((unit)->type))
  92.  
  93. /* Extractor for the actual altitude of an airborne unit. */
  94.  
  95. #define unit_alt(unit) ((unit)->z & 1 == 0 ? ((unit)->z >> 1) : 0)
  96.  
  97. /* Extractor for the connection a unit is on. */
  98.  
  99. #define unit_conn(unit) ((unit)->z & 1 == 1 ? ((unit)->z >> 1) : NONTTYPE)
  100.  
  101. /* This is true if the unit is on the board somewhere. */
  102.  
  103. #define is_present(unit) in_play(unit)
  104.  
  105. #define in_play(unit) \
  106.   (is_unit(unit) && alive(unit) && inside_area((unit)->x, (unit)->y))
  107.  
  108. #define in_action(unit) is_active(unit)
  109.  
  110. #define is_acting(unit) is_active(unit)
  111.  
  112. #define is_active(unit) (in_play(unit) && completed(unit))
  113.  
  114. /* Extractions for the two parts of an attitude/feeling. */
  115.  
  116. #define intensity(att) (((att) >> 8) & 0xff)
  117.  
  118. #define bias(att) (((att) & 0xff) - 128)
  119.  
  120. /* A sortable vector of units, generally useful. */
  121.  
  122. /* The kinds of sort keys available for list windows. */
  123.  
  124. enum sortkeys {
  125.     bynothing,
  126.     bytype,
  127.     byname,
  128.     byactorder,
  129.     bylocation,
  130.     byside,
  131.     numsortkeytypes
  132. };
  133.  
  134. /* Can sort on as many as five keys. */
  135.  
  136. #define MAXSORTKEYS 5
  137.  
  138. typedef struct a_unitvectorentry {
  139.     Unit *unit;
  140.     int flag;
  141. } UnitVectorEntry;
  142.  
  143. typedef struct a_unitvector {
  144.     int size;
  145.     int numunits;
  146.     enum sortkeys sortkeys[MAXSORTKEYS];
  147.     UnitVectorEntry units[1];
  148. } UnitVector;
  149.  
  150. /* Types of primitive unit actions. */
  151.  
  152. typedef enum actiontype {
  153.  
  154. #undef  DEF_ACTION
  155. #define DEF_ACTION(name,CODE,args,prepfn,dofn,checkfn,argdecl,doc) CODE,
  156.  
  157. #include "action.def"
  158.  
  159.     NUMACTIONTYPES
  160.  
  161. } ActionType;
  162.  
  163. typedef struct a_actiondefn {
  164.     ActionType typecode;
  165.     char *name;
  166.     char *argtypes;
  167. #ifdef THINK_C
  168.     int (*dofn) PROTO ((Unit *unit, Unit *unit2, ...));
  169.     int (*checkfn) PROTO ((Unit *unit, Unit *unit2, ...));
  170. #else
  171.     int (*dofn) PROTO (());
  172.     int (*checkfn) PROTO (());
  173. #endif
  174. } ActionDefn;
  175.  
  176. #define MAXACTIONARGS 4
  177.  
  178. typedef struct a_action {
  179.     ActionType type;        /* the type of the action */
  180.     short args[MAXACTIONARGS];    /* assorted parameters */
  181.     short actee;        /* the unit being affected by action */
  182.     struct a_action *next;    /* chain to next action */
  183. } Action;
  184.  
  185. typedef struct a_actorstate {
  186.     short initacp;        /* how much we can still do */
  187.     short acp;            /* how much we can still do */
  188.     short actualactions;    /* actions actually done this turn */
  189.     short actualmoves;        /* cells actually covered this turn */
  190.     Action nextaction;
  191. } ActorState;
  192.  
  193. #define valid(x) ((x) == A_ANY_OK)
  194.  
  195. #define has_pending_action(unit)  \
  196.   ((unit)->act && (unit)->act->nextaction.type != A_NONE)
  197.  
  198. /* All the definitions that govern planning. */
  199.  
  200. /* A goal is a predicate object that can be tested to see whether it has
  201.    been achieved.  As such, it is a relatively static object and may be
  202.    shared. */
  203.  
  204. /* The different types of goals. */
  205.  
  206. typedef enum goaltype {
  207.  
  208. #undef  DEF_GOAL
  209. #define DEF_GOAL(name,GOALTYPE,args) GOALTYPE,
  210.  
  211. #include "goal.def"
  212.  
  213.     g_t_dummy
  214. } GoalType;
  215.  
  216. typedef struct a_goaldefn {
  217.     char *name;
  218.     char *argtypes;
  219. } GoalDefn;
  220.  
  221. /* The goal structure proper. */
  222.  
  223. #define MAXGOALARGS 5
  224.  
  225. typedef struct a_goal {
  226.     GoalType type;
  227.     short tf;
  228.     Side *side;
  229.     short args[MAXGOALARGS];
  230. } Goal;
  231.  
  232. extern Goal *create_goal PROTO ((GoalType type, Side *side, int tf));
  233. extern int cell_unknown PROTO ((int x, int y));
  234. extern int enemies_present PROTO ((int x, int y));
  235. extern int goal_truth PROTO ((Side *side, Goal *goal));
  236. extern char *goal_desig PROTO ((Goal *goal));
  237.  
  238. /* A task is a single executable element of a unit's plan.  Each task type
  239.    is something that has been found useful or convenient to encapsulate as
  240.    a step in a plan. */
  241.  
  242. typedef enum a_tasktype {
  243.  
  244. #undef  DEF_TASK
  245. #define DEF_TASK(name,CODE,argtypes,fn) CODE,
  246.  
  247. #include "task.def"
  248.  
  249.     NUMTASKTYPES
  250. } TaskType;
  251.  
  252. typedef enum a_taskoutcome {
  253.   TASK_UNKNOWN,
  254.   TASK_FAILED,
  255.   TASK_IS_INCOMPLETE,
  256.   TASK_PREPPED_ACTION,
  257.   TASK_IS_COMPLETE
  258. } TaskOutcome;
  259.  
  260. #define MAXTASKARGS 6
  261.  
  262. typedef struct a_task {
  263.     TaskType type;        /* the kind of task we want to do */
  264.     short args[MAXTASKARGS];    /* arguments */
  265.     short execnum;        /* how many times this has been done */
  266.     short retrynum;        /* number of immed failures so far */
  267.     struct a_task *next;    /* the next task to undertake */
  268. } Task;
  269.  
  270. typedef struct a_taskdefn {
  271.     char *name;
  272.     char *argtypes;
  273.     TaskOutcome (*exec) PROTO ((Unit *unit, Task *task));
  274. } TaskDefn;
  275.  
  276. /* A plan is what a single unit uses to make decisions, both for itself and
  277.    for any other units it commands.  Any unit that can act at all has a
  278.    plan object.  A plan collects lots of unit behavior, but its most
  279.    important structure is the task queue, which contains a list of what
  280.    to do next, in order. */
  281.  
  282. /* Plan types distinguish several kinds of usages. */
  283.  
  284. typedef enum plantype {
  285.  
  286. #undef  DEF_PLAN
  287. #define DEF_PLAN(name,CODE) CODE,
  288.  
  289. #include "plan.def"
  290.  
  291.     NUMPLANTYPES
  292. } PlanType;
  293.  
  294. typedef struct a_plan {
  295.     PlanType type;        /* general type of plan that we've got here */
  296.     short creationturn;        /* turn at which this plan was created */
  297.     short startturn;        /* turn at which this plan is to be done */
  298.     short endturn;        /* turn to deactivate this plan */
  299.     short asleep;        /* true if the unit is doing nothing */
  300.     short reserve;        /* true if unit waiting until next turn */
  301.     short delayed;
  302.     short waitingfortasks;    /* true if waiting to be given a task */
  303.     short autotask;        /* true if will try to generate own tasks */
  304.     short aicontrol;        /* true if an AI can operate on the unit */
  305.     short supply_alarm;
  306.     short supply_is_low;
  307.     short waitingfortransport;
  308.     struct a_goal *maingoal;    /* the main goal of this plan */
  309.     struct a_goal *formation;    /* goal to keep in a formation */
  310.     struct a_task *tasks;    /* pointer to chain of sequential tasks */
  311.     /* Not saved/restored. (little value, some trouble to do) */
  312.     struct a_unit *funit;    /* pointer to unit keeping formation */
  313.     Action lastaction;         /* a copy of the last action attempted */
  314.     short lastresult;        /* that action's outcome */
  315. } Plan;
  316.  
  317. /* Global unit variables. */
  318.  
  319. extern Unit *unitlist;
  320. extern Unit *tmpunit;
  321.  
  322. extern int numunits;
  323.  
  324. extern enum sortkeys tmpsortkeys[];
  325.  
  326. extern ActionDefn actiondefns[];
  327.  
  328. extern GoalDefn goaldefns[];
  329.  
  330. extern TaskDefn taskdefns[];
  331.  
  332. extern char *plantypenames[];
  333.  
  334. /* Declarations of unit-related functions. */
  335.  
  336. extern void allocate_unit_block PROTO ((void));
  337. extern void init_units PROTO ((void));
  338. extern Unit *create_bare_unit PROTO ((int type));
  339. extern Unit *create_unit PROTO ((int type, int makebrains));
  340. extern void init_unit_actorstate PROTO ((Unit *unit));
  341. extern void init_unit_plan PROTO ((Unit *unit));
  342. extern void init_unit_tooling PROTO ((Unit *unit));
  343. extern void init_unit_opinions PROTO ((Unit *unit));
  344. extern Unit *designer_create_unit PROTO ((Side *side, int u, int s, int x, int y));
  345. extern void change_unit_type PROTO ((Unit *unit, int newtype, int reason));
  346. extern int max_builds PROTO ((int u));
  347. extern int enter_cell PROTO ((Unit *unit, int x, int y));
  348. extern int can_occupy_cell PROTO ((Unit *unit, int x, int y));
  349. extern int type_can_occupy_cell PROTO ((int u, int x, int y));
  350. extern int can_occupy_cell_without PROTO ((Unit *unit, int x, int y, Unit *unit3));
  351. extern int type_can_occupy_cell_without PROTO ((int u, int x, int y, Unit *unit3));
  352. extern void enter_cell_aux PROTO ((Unit *unit, int x, int y));
  353. extern int can_occupy PROTO ((Unit *unit, Unit *transport));
  354. extern int can_carry PROTO ((Unit *transport, Unit *unit));
  355. extern int type_can_occupy PROTO ((int u, Unit *transport));
  356. extern int can_occupy_type PROTO ((Unit *unit, int u2));
  357. extern int can_carry_type PROTO ((Unit *transport, int u));
  358. extern void enter_transport PROTO ((Unit *unit, Unit *transport));
  359. extern void leave_cell PROTO ((Unit *unit));
  360. extern void leave_cell_aux PROTO ((Unit *unit));
  361. extern void leave_transport PROTO ((Unit *unit));
  362. extern void eject_excess_occupants PROTO ((Unit *unit));
  363. extern void eject_occupant PROTO ((Unit *unit, Unit *occ));
  364. extern void unit_changes_side PROTO ((Unit *unit, Side *newside, int reason1, int reason2));
  365. extern int unit_allowed_on_side PROTO ((Unit *unit, Side *side));
  366. extern int test_class_membership PROTO ((Obj *leaf));
  367. extern int type_allowed_on_side PROTO ((int u, Side *side));
  368. extern int unit_trusts_unit PROTO ((Unit *unit1, Unit *unit2));
  369. extern int set_unit_side PROTO ((Unit *unit, Side *side));
  370. extern void set_unit_plan_type PROTO ((Side *side, Unit *unit, int type));
  371. extern void set_unit_asleep PROTO ((Side *side, Unit *unit, int flag, int recurse));
  372. extern void set_unit_reserve PROTO ((Side *side, Unit *unit, int flag, int recurse));
  373. extern void set_unit_ai_control PROTO ((Side *side, Unit *unit, int flag, int recurse));
  374. extern void set_unit_name PROTO ((Side *side, Unit *unit, char *newname));
  375. extern void kill_unit PROTO ((Unit *unit, int reason));
  376. extern void kill_unit_aux PROTO ((Unit *unit, int reason));
  377. extern void react_to_unit_loss PROTO ((Side *side, Unit *unit, int reason));
  378. extern void dispose_of_plan PROTO ((Unit *unit));
  379. extern void flush_dead_units PROTO ((void));
  380. extern void put_unit_on_dead_list PROTO ((Unit *unit));
  381. extern void flush_side_dead PROTO ((Side *side));
  382. extern void flush_one_unit PROTO ((Unit *unit));
  383. extern void sort_units PROTO ((void));
  384. extern int moves_till_low_supplies PROTO ((Unit *unit));
  385. extern char *unit_desig PROTO ((Unit *unit));
  386. extern char *unit_desig_no_loc PROTO ((Unit *unit));
  387. extern char *utype_name_n PROTO ((int u, int n));
  388. extern char *shortest_unique_name PROTO ((int u));
  389. extern char *actorstate_desig PROTO ((struct a_actorstate *as));
  390. extern Unit *find_unit PROTO ((int n));
  391. extern Unit *find_unit_by_name PROTO ((char *nm));
  392. extern Unit *find_unit_by_number PROTO ((int nb));
  393. extern Unit *find_unit_dead_or_alive PROTO ((int n));
  394. extern int find_unit_name PROTO ((char *str));
  395. extern Unit *first_unit PROTO ((Side *side));
  396. extern void insert_unit PROTO ((Unit *unithead, Unit *unit));
  397. extern void delete_unit PROTO ((Unit *unit));
  398. extern int num_occupants PROTO ((Unit *unit));
  399. extern int num_units_at PROTO ((int x, int y));
  400. extern void check_all_units PROTO ((void));
  401. extern void check_unit PROTO ((Unit *unit));
  402. extern void designer_teleport PROTO ((Unit *unit, int x, int y));
  403. extern UnitVector *make_unit_vector PROTO ((int initsize));
  404. extern void clear_unit_vector PROTO ((UnitVector *vec));
  405. extern UnitVector *add_unit_to_vector PROTO ((UnitVector *vec, Unit *unit, int flag));
  406. extern void remove_unit_from_vector PROTO ((UnitVector *vec, Unit *unit, int pos));
  407. extern void sort_unit_vector PROTO ((UnitVector *vec));
  408. extern Obj *get_x_property PROTO ((Unit *unit, int subkey));
  409. extern Obj *get_x_property_by_name PROTO ((Unit *unit, char *str));
  410.  
  411. /* Declarations of plan-related functions. */
  412.  
  413. extern void execute_plan PROTO ((Unit *unit, int try));
  414. extern int move_into_formation PROTO ((Unit *unit));
  415. extern void plan_offense PROTO ((Unit *unit));
  416. extern int do_for_occupants PROTO ((Unit *unit));
  417. extern void plan_offense_support PROTO ((Unit *unit));
  418. extern void set_construction PROTO ((Unit *unit, int u, int num));
  419. extern void plan_defense PROTO ((Unit *unit));
  420. extern void plan_exploration PROTO ((Unit *unit));
  421. extern void plan_explorer_support PROTO ((Unit *unit));
  422. extern int victim_here PROTO ((int x, int y));
  423. extern int worth_capturing PROTO ((Side *side, int u2, Side *oside, int x, int y));
  424. extern int go_after_victim PROTO ((Unit *unit, int range));
  425. extern int target_here PROTO ((int x, int y));
  426. extern int fire_at_opportunity PROTO ((Unit *unit));
  427. extern int resupply_if_low PROTO ((Unit *unit));
  428. extern int rearm_if_low PROTO ((Unit *unit));
  429. extern int supplies_here PROTO ((Unit *unit, int x, int y, int m));
  430. extern int indep_captureable_here PROTO ((int x, int y));
  431. extern int capture_indep_if_nearby PROTO ((Unit *unit));
  432. extern int useful_captureable_here PROTO ((int x, int y));
  433. extern int useful_type PROTO ((Side *side, int u));
  434. extern int capture_useful_if_nearby PROTO ((Unit *unit));
  435. extern int could_capture_any PROTO ((int u));
  436. extern void plan_random PROTO ((Unit *unit));
  437. extern void make_plausible_random_args PROTO ((char *argtypestr, int i, short *args, Unit *unit));
  438. extern void decide_plan PROTO ((Side *side, Unit *unit));
  439. extern int doctrine_allows_wait PROTO ((Unit *unit));
  440. extern void wait_for_orders PROTO ((Unit *unit));
  441. extern void decide_tasks PROTO ((Unit *unit));
  442. extern void random_walk PROTO ((Unit *unit));
  443. extern void reserve_unit PROTO ((Side *side, Unit *unit));
  444. extern void wake_unit PROTO ((Unit *unit, int wakeocc, int reason, Unit *unit2));
  445. extern void wake_area PROTO ((Side *side, int x, int y, int n, int occs));
  446. extern void set_formation PROTO ((Unit *unit, Unit *leader, int x, int y, int dist, int flex));
  447. extern void delay_unit PROTO ((Unit *unit, int flag));
  448. extern int find_base PROTO ((Unit *unit, int (*pred)(void), int extra));
  449. extern int maybe_return_home PROTO ((Unit *unit));
  450. extern int range_left PROTO ((Unit *unit));
  451. extern void plan_exploration_route PROTO ((Unit *unit, int x, int y));
  452. extern int route_to PROTO ((Unit *unit, int x, int y));
  453. extern int find_worths PROTO ((int range));
  454. extern int attack_worth PROTO ((Unit *unit, int e));
  455. extern int threat PROTO ((Side *side, int u, int x0, int y0));
  456. extern int should_build_base PROTO ((Unit *unit));
  457. extern int region_portion PROTO ((int n, int u, int *units_close, int *adjterr));
  458. extern void pop_task PROTO ((Plan *plan));
  459. extern int react_to_enemies PROTO ((Unit *unit));
  460. extern int move_patrol PROTO ((Unit *unit));
  461. extern int build_time PROTO ((Unit *unit, int prod));
  462. extern void clear_task_agenda PROTO ((Plan *plan));
  463. extern Plan *create_plan PROTO ((void));
  464. extern void free_plan PROTO ((Plan *plan));
  465. extern char *plan_desig PROTO ((Plan *plan));
  466. extern int might_be_captured PROTO ((Unit *unit));
  467. extern void force_global_replan PROTO ((Side *side));
  468. extern int units_nearby PROTO ((int x, int y, int dist, int type));
  469. extern int survive_to_build_base PROTO ((Unit *unit));
  470. extern int exact_survive_to_build_base PROTO ((Unit *unit));
  471. extern int base_here PROTO ((int x, int y));
  472. extern int any_base_here PROTO ((int x, int y));
  473. extern int neutral_base_here PROTO ((int x, int y));
  474. extern int base_nearby PROTO ((Unit *unit, int range));
  475. extern int any_base_nearby PROTO ((Unit *unit, int range));
  476. extern int neutral_base_nearby PROTO ((Unit *unit, int range));
  477. extern int occupant_could_capture PROTO ((Unit *unit, int etype));
  478. extern int can_capture_neighbor PROTO ((Unit *unit));
  479. extern int occupant_can_capture_neighbor PROTO ((Unit *unit));
  480. extern int find_closest_unit PROTO ((Side *side, int x0, int y0, int maxdist, int (*pred)(void), int *rxp, int *ryp));
  481. extern int fullness PROTO ((Unit *unit));
  482. extern int can_build PROTO ((Unit *unit));
  483. extern int can_move PROTO ((Unit *unit));
  484. extern int out_of_ammo PROTO ((Unit *unit));
  485. extern int good_haven_p PROTO ((Side *side, int x, int y));
  486. extern int haven_p PROTO ((Unit *unit, int x, int y));
  487. extern int shop_p PROTO ((Unit *unit, int x, int y));
  488. extern int survival_time PROTO ((Unit *unit));
  489. extern long regions_around PROTO ((int u, int x, int y, int center));
  490. extern Task *make_route_step PROTO ((int x, int y, int priority));
  491. extern Task *make_route_chain PROTO ((int sx, int sy, int tx, int ty));
  492. extern Task *find_route_aux PROTO ((Unit *unit, int maxdist, int curlen, int fromdir, int sx, int sy, int fx, int fy, int tx, int ty, int flags));
  493. extern int usable_cell PROTO ((Unit *unit, int x, int y));
  494. extern Task *find_route PROTO ((Unit *unit, int maxdist, int tx, int ty));
  495. extern Task *find_route_aux_nearest PROTO ((Unit *unit, int maxdist, int curlen, int fromdir, int sx, int sy, int fx, int fy, int (*pathpred)(void), int (*destpred)(void), int flags));
  496. extern Task *find_route_to_nearest PROTO ((Unit *unit, int fx, int fy, int maxdist, int (*pathpred)(void), int (*destpred)(void)));
  497. extern int explorable_cell PROTO ((int x, int y));
  498. extern int reachable_unknown PROTO ((int x, int y));
  499. extern int adj_known_ok_terrain PROTO ((int x, int y, Side *side, int u));
  500. extern int explore_reachable_cell PROTO ((Unit *unit, int range));
  501. extern int optimize_plan PROTO ((Unit *unit));
  502. extern int should_capture_maker PROTO ((Unit *unit));
  503. extern int no_possible_moves PROTO ((Unit *unit));
  504. extern int adj_known_passable PROTO ((Side *side, int x, int y, int u));
  505. extern int adj_obstacle PROTO ((int type, int x, int y));
  506. extern int normal_completion_time PROTO ((int u, int u2));
  507. extern int adj_unit PROTO ((int x, int y));
  508. extern int past_halfway_point PROTO ((Unit *unit));
  509.  
  510. extern int self_build_base_for_self PROTO ((Unit *unit));
  511.  
  512. extern int operating_range_worst PROTO ((int u));
  513. extern int operating_range_best PROTO ((int u));
  514.  
  515. extern int terrain_always_impassable PROTO ((int u, int t));
  516.  
  517. /* Declarations of task-related functions. */
  518.  
  519. extern void init_tasks PROTO ((void));
  520. extern void allocate_task_block PROTO ((void));
  521. extern Task *create_task PROTO ((TaskType type));
  522. extern int fire_can_damage PROTO ((Unit *unit, Unit *unit2));
  523. extern Unit *repair_here PROTO ((int x, int y));
  524. extern Unit *aux_resupply_here PROTO ((Unit *unit));
  525. extern Unit *resupply_here PROTO ((int x, int y));
  526. extern int can_auto_resupply_self PROTO ((Unit *unit, int *materials, int numtypes));
  527. extern TaskOutcome execute_task PROTO ((Unit *unit));
  528. extern TaskOutcome execute_task_aux PROTO ((Unit *unit, Task *task));
  529. extern int choose_move_dirs PROTO ((Unit *unit, int tx, int ty, int shortest, int (*dirtest)(Unit *, int), void (*dirsort)(Unit *, int *, int), int *dirs));
  530. extern int plausible_move_dir PROTO ((Unit *unit, int dir));
  531. extern void sort_directions PROTO ((Unit *unit, int *dirs, int numdirs));
  532. extern void free_task PROTO ((Task *task));
  533. extern void be_active PROTO ((Unit *unit));
  534. extern Task *create_sentry_task PROTO ((int n));
  535. extern void push_sentry_task PROTO ((Unit *unit, int n));
  536. extern Task *create_moveto_task PROTO ((int x, int y));
  537. extern void order_sentry PROTO ((Unit *unit, int n));
  538. extern void push_moveto_task PROTO ((Unit *unit, int x, int y));
  539. extern void order_moveto PROTO ((Unit *unit, int x, int y));
  540. extern void set_moveto_task PROTO ((Unit *unit, int x, int y));
  541. extern Task *create_movenear_task PROTO ((int x, int y, int dist));
  542. extern void set_movenear_task PROTO ((Unit *unit, int x, int y, int dist));
  543. extern void push_movenear_task PROTO ((Unit *unit, int x, int y, int dist));
  544. extern void order_movenear PROTO ((Unit *unit, int x, int y));
  545. extern Task *create_movedir_task PROTO ((int dir, int n));
  546. extern void set_movedir_task PROTO ((Unit *unit, int dir, int n));
  547. extern Task *create_build_task PROTO ((int u2, int run));
  548. extern void push_build_task PROTO ((Unit *unit, int u2, int run));
  549. extern Task *create_research_task PROTO ((int u2, int n));
  550. extern void push_research_task PROTO ((Unit *unit, int u2, int n));
  551. extern void set_hit_task PROTO ((Unit *unit, int x, int y));
  552. extern void push_specific_hit_task PROTO ((Unit *unit, int x, int y, int u, int s));
  553. extern void set_specific_hit_task PROTO ((Unit *unit, int x, int y, int u, int s));
  554. extern void push_hit_task PROTO ((Unit *unit, int x, int y));
  555. extern void set_capture_task PROTO ((Unit *unit, int x, int y));
  556. extern void push_capture_task PROTO ((Unit *unit, int x, int y));
  557. extern void set_resupply_task PROTO ((Unit *unit));
  558. extern Task *create_occupy_task PROTO ((Unit *transport));
  559. extern void push_occupy_task PROTO ((Unit *unit, Unit *transp));
  560. extern Task *create_pickup_task PROTO ((Unit *occ));
  561. extern void push_pickup_task PROTO ((Unit *unit, Unit *occ));
  562. extern int tasked_unit_valid PROTO ((Unit *unit, char *tasktypename));
  563. extern char *task_desig PROTO ((Task *task));
  564.  
  565. extern int repair_test PROTO ((int x, int y));
  566. extern int resupply_test PROTO ((int x, int y));
  567.  
  568. #undef  DEF_ACTION
  569. #define DEF_ACTION(name,code,args,PREPFN,dofn,CHECKFN,ARGDECL,doc)  \
  570.   extern int PREPFN  PROTO (ARGDECL);  \
  571.   extern int CHECKFN PROTO (ARGDECL);
  572.  
  573. #include "action.def"
  574.  
  575.